package com.lingshi.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingshi.shopping_common.entity.SeckillGoods;
import com.lingshi.shopping_common.result.BaseResult;
import com.lingshi.shopping_common.service.ISeckillGoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀商品
 */
@RestController
@RequestMapping("/seckillGoods")
public class SeckillGoodsController {

    @DubboReference
    private ISeckillGoodsService seckillGoodsService;

    /**
     * 添加秒杀商品
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody SeckillGoods seckillGoods) {
        seckillGoodsService.add(seckillGoods);
        return BaseResult.success();
    }

    /**
     * 修改秒杀商品
     */
    @PutMapping("/update")
    public BaseResult update(@RequestBody SeckillGoods seckillGoods) {
        seckillGoodsService.update(seckillGoods);
        return BaseResult.success();
    }

    /**
     * 分页查询秒杀商品
     */
    @GetMapping("/findPage")
    public BaseResult findPage(@RequestParam(defaultValue = "1")Integer page,
                               @RequestParam(defaultValue = "10") Integer size) {
        Page<SeckillGoods> search = seckillGoodsService.findPage(page, size);
        return BaseResult.success(search);
    }
}
